/**
 * Copyright (C) 2011 Vinicius Vielmo Cogo, Marcelo Pasin, and the authors
 * indicated in the @author tags.
 * 
 * This file is part of DiversityAgent.
 * 
 * DiversityAgent is a free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or (at your
 * option) any later version.
 * 
 * DiversityAgent is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with DiversityAgent. If not, see <http://www.gnu.org/licenses/>.
 */
package diversity_agent;

import java.util.Properties;

/**
 * This is an abstract class that represents the cloud drivers.
 * 
 * @author Vinicius Vielmo Cogo (vielmo at lasige.di.fc.ul.pt)
 * @version 0.1-beta
 * @since 2011-11-18
 * 
 */
public abstract class Cloud
{
	private String	mTool;
	private String	mType;
	private String	mCloudName;
	private String	mIpAddress;
	protected int	mRunningVms;
	protected int	mCreatedVms;
	// Used to block temporarily the cloud if something failed on it.
	private boolean	mBlocked;

	/**
	 * 
	 * @param theCloudName
	 * @param theTool
	 * @param theType
	 * @param theIpAddress
	 */
	public Cloud(String theCloudName, String theTool, String theType,
			String theIpAddress)
	{
		this.mCloudName = theCloudName;
		this.mTool = theTool;
		this.mType = theType;
		this.mIpAddress = theIpAddress;
		this.mRunningVms = 0;
		this.mCreatedVms = 0;
		this.mBlocked = false;
	}

	/**
	 * 
	 * @param theProperties
	 * @param theDataContainer
	 * @return
	 */
	public abstract VirtualMachine createVm(Properties theProperties,
			DataContainer theDataContainer);

	/**
	 * 
	 * @param theVmIdOnCloud
	 * @param theProperty
	 * @return
	 */
	public abstract String readVm(int theVmIdOnCloud, String theProperty);

	/**
	 * 
	 * @return
	 */
	public abstract boolean updateVm();

	/**
	 * 
	 * @param theVmIdOnCloud
	 * @return
	 */
	public abstract boolean deleteVm(int theVmIdOnCloud);

	/**
	 * 
	 * @param theVmIdOnCloud
	 * @return
	 */
	public abstract String getVmStatus(int theVmIdOnCloud);

	/**
	 * 
	 * @return
	 */
	public String getCloudName()
	{
		return mCloudName;
	}

	/**
	 * 
	 * @return
	 */
	public String getIpAddress()
	{
		return this.mIpAddress;
	}

	/**
	 * 
	 * @return
	 */
	public String getTool()
	{
		return this.mTool;
	}

	/**
	 * 
	 * @return
	 */
	public String getType()
	{
		return this.mType;
	}

	/**
	 * 
	 */
	public void incrementCreatedVms()
	{
		this.mCreatedVms++;
	}

	/**
	 * 
	 * @return
	 */
	public int countCreatedVms()
	{
		return this.mCreatedVms;
	}

	/**
	 * 
	 */
	public void incrementRunningVms()
	{
		this.mRunningVms++;
	}

	/**
	 * 
	 */
	public void decrementRunningVms()
	{
		this.mRunningVms--;
	}

	/**
	 * 
	 * @return
	 */
	public int countRunningVms()
	{
		return this.mRunningVms;
	}

	/**
	 * 
	 */
	public void block()
	{
		this.mBlocked = true;
	}

	/**
	 * 
	 */
	public void unblock()
	{
		this.mBlocked = false;
	}

	/**
	 * 
	 * @return
	 */
	public boolean isBlocked()
	{
		return this.mBlocked;
	}
}
